package com.br.android.widingwheels.maps;

import java.util.ArrayList;
import java.util.List;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.Toast;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;
import com.readystatesoftware.mapviewballoons.BalloonItemizedOverlay;

public class MeuItemizedOverlay extends BalloonItemizedOverlay<OverlayItem> {

	private List<OverlayItem> listOverlay = new ArrayList<OverlayItem>();
	private Context context;

	public MeuItemizedOverlay(Drawable drawable, MapView mapView) {
		super(boundCenterBottom(drawable), mapView);
	}

	public MeuItemizedOverlay(Drawable drawable, Context context, MapView mapView){
		super(boundCenterBottom(drawable), mapView);
		this.context = context;
	}

	public void addOverlay(OverlayItem overlay){
		listOverlay.add(overlay);
	}

	@Override
	protected OverlayItem createItem(int intValue) {
		return listOverlay.get(intValue);
	}

	@Override
	public int size() {
		return listOverlay.size();
	}

	public boolean onBalloonTap(int i) {
		//when you tap on the marker this will show the informations provided by you when you create in the
        //main class the OverlayItem
        OverlayItem item = listOverlay.get(i);
//        AlertDialog.Builder dialog = new AlertDialog.Builder(context);
//        dialog.setTitle(item.getTitle());
//        dialog.setMessage(item.getSnippet());
//        dialog.show();
        Toast.makeText(context, item.getTitle(), Toast.LENGTH_SHORT).show();
        return true;
	}

	public void populateNow(){
		populate();
	}

}
